home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d16 / winvn060.arc / WVPOST.C < prev    next >
C/C++ Source or Header  |  1991-07-01  |  8KB  |  292 lines

  1. /*--- WVPOST.C ------------------------------------------------------------
  2.  *
  3.  *    This file contains the window procedure for the "posting" windows,
  4.  *    windows in which the user edits the text of an article to be posted.
  5.  *
  6.  *    Mark Riordan   27 Jan 1990
  7.  */
  8.  
  9. #include "windows.h"
  10. #include "wvglob.h"
  11. #include "winvn.h"
  12. #ifndef MAC
  13. #include "winundoc.h"
  14. #endif
  15.  
  16. long FAR PASCAL WinVnPostWndProc(hWnd, message, wParam, lParam)
  17. HWND hWnd;
  18. unsigned message;
  19. WORD wParam;
  20. LONG lParam;
  21. {
  22.     FARPROC lpProcAbout;
  23.     HMENU hMenu;
  24.  
  25.     PAINTSTRUCT ps;                              /* paint structure          */
  26.  
  27.     HDC hDC;                                    /* handle to display context */
  28.     HWND hWndPost, hWndPostEdit;
  29. #ifdef MAC
  30.    TEHandle TEH;
  31.    Rect myClipRect;
  32. #endif
  33.     HDC  hDCView;
  34.     int ih,j;
  35.     int found;
  36.     int imemo;
  37.    TypDoc *MyDoc;
  38.     char mesbuf[348];  /*** debug */
  39.  
  40.     for(ih=0,found=FALSE; !found && ih<MAXPOSTWNDS; ih++) {
  41.       if(hWndPosts[ih] == hWnd) {
  42. #ifndef MAC
  43.          hWndPostEdit = hWndPostEdits[ih];
  44. #else 
  45.          TEH = TEHPosts[ih];
  46. #endif
  47.          found = TRUE;
  48.          break;
  49.       }
  50.     }
  51.    if(!found && message == WM_CREATE) {
  52.       for(ih=0; !found && ih<MAXVIEWS; ih++) {
  53.          if(!hWndPosts[ih]) {
  54.             found = TRUE;
  55.             hWndPosts[ih] = hWnd;
  56.             break;
  57.           }
  58.       }
  59.    }
  60. #if 0
  61.    if(!found) {
  62.       MessageBox(hWnd,"Can't find Post hWnd","Error!",MB_OK|MB_ICONHAND);
  63.       DestroyWindow(hWnd);
  64.       return(NULL);  /*** ? */
  65.    }
  66. #endif
  67.  
  68.    switch (message) {
  69.       case WM_SYSCOMMAND:
  70.          return (DefWindowProc(hWnd, message, wParam, lParam));
  71.  
  72.       case WM_CREATE:
  73. #ifndef MAC
  74.             hWndPostEdit = hWndPostEdits[ih] = CreateWindow("edit", (char *)NULL,
  75.                 WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | WS_BORDER
  76.                     | ES_LEFT | ES_MULTILINE |
  77.                     ES_AUTOHSCROLL | ES_AUTOVSCROLL
  78.                     ,
  79.                 0, 0, 0, 0,
  80.                 hWnd, EDITID, hInst, NULL);
  81.             sprintf(mesbuf,"hWndPostEdits[%d] = %5d\r\n       ",ih,hWndPostEdits[ih]);
  82.        /*   MessageBox(hWnd,mesbuf,"Edit Window Results",MB_OK|MB_ICONASTERISK); */
  83.             SetWindowText(hWndPostEdits[ih],mesbuf);
  84. #endif
  85. #if 0
  86.             { long int freeHeap = FreeMem();
  87.                long int biggestBlock = MaxBlock();
  88.                long int freeStack = StackSpace();
  89.                long int el;
  90.  
  91.                el = 0;
  92.                sprintf(mesbuf,"FreeMem=%ld  MaxBlock=%ld  StackSpace=%ld",
  93.                   freeHeap,biggestBlock,freeStack);
  94.                MessageBox(hWnd,mesbuf,"Available Memory",MB_OK);
  95.             }
  96. #endif
  97.             CreatePostingText(PostDoc,hWnd,hWndPostEdit,DOCTYPE_POSTING);
  98.        /*   SetFocus(hWndEdits[ih]);  */
  99.             break;
  100.  
  101.       case WM_SIZE:
  102. #ifndef MAC
  103.             MoveWindow(hWndPostEdit, 0, 0, LOWORD(lParam),
  104.                 HIWORD(lParam), TRUE);
  105. #endif
  106.             break;
  107.  
  108.       case WM_SETFOCUS:
  109.             SetFocus(hWndPostEdit);
  110.             break;
  111.  
  112.       case WM_KEYDOWN:
  113.          if(wParam == VK_F6) {
  114.             NextWindow(&(PostingDocs[ih]));
  115.          }
  116.          break;
  117.  
  118. #ifdef MAC
  119.       case WM_PAINT:
  120.          if(TEH) {
  121.             myClipRect = hWnd->portRect;
  122.             myClipRect.right -= SBarWidth;
  123.             myClipRect.bottom -= SBarWidth;
  124.             (*TEH)->viewRect = myClipRect;
  125.             TEUpdate(&myClipRect,TEH);
  126.          }
  127.          break;
  128.  
  129. #endif
  130.  
  131.       case WM_COMMAND:
  132.          switch(wParam) {
  133.             case IDM_CANCEL:
  134.             case IDV_EXIT:
  135.                DestroyWindow(hWnd);
  136.                break;
  137.  
  138.             case IDM_POST:
  139.                StartPost(ih);
  140.                break;
  141.  
  142.             case IDM_UNDO:
  143.                SendMessage(hWndPostEdit, WM_UNDO, 0, 0L);
  144.                break;
  145.  
  146.             case IDM_CUT:
  147.                SendMessage(hWndPostEdit, WM_CUT, 0, 0L);
  148.                break;
  149.  
  150.             case IDM_COPY:
  151.                SendMessage(hWndPostEdit, WM_COPY, 0, 0L);
  152.                break;
  153.  
  154.             case IDM_PASTE:
  155.                SendMessage(hWndPostEdit, WM_PASTE, 0, 0L);
  156.                break;
  157.  
  158.             case IDM_CLEAR:
  159.                SendMessage(hWndPostEdit, WM_CLEAR, 0, 0L);
  160.                break;
  161.  
  162.             case IDM_SELALL:
  163.                SendMessage(hWndPostEdit, EM_SETSEL, 0,
  164.                 MAKELONG(0,32767));
  165.                break;
  166.  
  167.          }
  168.             break;
  169.  
  170.  
  171.         case WM_DESTROY:
  172.             hWndPosts[ih] = 0;
  173. #ifndef MAC
  174.             hWndPostEdits[ih] = 0;
  175. #else
  176.             TEDispose(TEHPosts[ih]);
  177.             TEHPosts[ih] = (TEHandle) 0;
  178.             TEHCurrent = 0;
  179. #endif
  180.             break;
  181.  
  182.  
  183.         default:
  184.             return (DefWindowProc(hWnd, message, wParam, lParam));
  185.     }
  186.     return (0L);
  187. }
  188.  
  189. /*--- function StartPost ----------------------------------------------
  190.  *
  191.  *    Start the posting procedure for an article that has been created
  192.  *    by the user.
  193.  *
  194.  *    Entry    ih    is the index into hWndPostEdits of the child
  195.  *                   edit window containing the article.
  196.  */
  197. BOOL
  198. StartPost(ih)
  199. int ih;
  200. {
  201.    BOOL found;
  202.    BOOL PostOK = FALSE;
  203.    char outline[MAXOUTLINE];
  204.  
  205.    if(CommBusy) {
  206.       MessageBox(hWndPosts[ih],"Sorry, I am already busy retrieving information from the server.\n\
  207. Try again in a little while.","Can't post article right now",MB_OK|MB_ICONASTERISK);
  208.    } else {
  209.       CommLinePtr = CommLineIn;
  210.       CommBusy = TRUE;
  211.       CommState = ST_POST_WAIT_PERMISSION;
  212.       CommDoc =  &(PostingDocs[ih]);
  213.  
  214.       strcpy(outline,"POST");
  215.       PutCommLine(outline,strlen(outline));
  216.       PostOK = TRUE;
  217.    }
  218.    return(PostOK);
  219. }
  220.  
  221. /*--- function PostText -------------------------------------------------
  222.  *
  223.  *    Post the text of an article.  (Second phase of posting process.)
  224.  *
  225.  *    Entry    ih    is the index into hWndPostEdits of the child
  226.  *                   edit window containing the article.
  227.  */
  228. BOOL
  229. PostText(ih,DocType)
  230. int ih;
  231. int DocType;
  232. {
  233. #ifndef MAC
  234.    HWND hWndPostEdit;
  235. #else
  236.    TEHandle TEH = TEHPosts[ih];
  237. #endif
  238.    char outline[MAXOUTLINE];
  239.    char *outptr;
  240.    char *editptr;
  241.    HANDLE hEditBuffer;
  242.    int linelen;
  243.    BOOL EndBuf=FALSE;
  244.  
  245. #ifndef MAC
  246.    if(DocType == DOCTYPE_POSTING) {
  247.       hWndPostEdit = hWndPostEdits[ih];
  248.       CommState = ST_POST_WAIT_END;
  249.    } else {
  250.       hWndPostEdit = hWndMailEdits[ih];
  251.       CommState = ST_MAIL_WAIT_END;
  252.    }
  253. #endif
  254.  
  255.    /* Retrieve the text of the edit window, and run through it
  256.     * line by line, sending the lines to the server.
  257.     */
  258. #ifndef MAC
  259.    hEditBuffer = (HANDLE) SendMessage(hWndPostEdit,EM_GETHANDLE,0,0L);
  260.    editptr = LocalLock(hEditBuffer);
  261. #else
  262.    hEditBuffer = TEGetText(TEH);
  263.    editptr = LocalLock(hEditBuffer);
  264.    editptr[(*TEH)->teLength] = '\0';
  265.    
  266. #ifdef MRRBUG
  267.    sprintf(outline,"PostText after TEGetText, editptr=%.30s",editptr);
  268.    MessageBox((HWND) 0,outline,"",MB_OK);
  269. #endif
  270.  
  271. #endif
  272.    while(!EndBuf) {
  273.       for(linelen = 0, outptr = outline; *editptr && *editptr!='\r' &&
  274.         linelen < MAXOUTLINE; linelen++) *(outptr++) = *(editptr++);
  275.       PutCommLine(outline,linelen);
  276. #ifdef MRRBUG
  277.       outline[linelen] = '\0';
  278.       MessageBox((HWND) 0,outline,"Posted line",MB_OK);
  279. #endif
  280.       if(*editptr == '\r') editptr++;
  281.       if(*editptr == '\n') editptr++;
  282.       if(!*editptr) {
  283.          EndBuf = TRUE;
  284.       }
  285.    }
  286. #if 1
  287.    LocalUnlock(hEditBuffer);
  288. #endif
  289.    PutCommLine(".",1);
  290.    return(TRUE);
  291. }
  292.